package Demo;


import java.awt.Color;
import java.math.BigInteger;

public class Solution {

	public String chromosome;
	public int fitness = 1;
	public float height1;
	public float height2;
	public float side1; 
	public float side2;
	public float sharedSide;
	public float wheel1;
	public float wheel2;
	public Color color;
	public Color wheelColor;
	
	public Solution()
	{
		chromosome = GenerateGenome(15);
		this.ParseGenome();
	}
	
	public Solution(String c)
	{
		chromosome = c;
		this.ParseGenome();
	}
	
	private void ParseGenome()
	{
		int index = 0;
		BigInteger bi = new BigInteger(chromosome.substring(index, index + 8), 2);
		height1 = bi.intValue() % 10 - 5;
		index+=8;
		bi = new BigInteger(chromosome.substring(index, index + 8), 2);
		height2 = bi.intValue() % 10 - 5;
		index+=8;
		bi = new BigInteger(chromosome.substring(index, index + 8), 2);
		side1 = bi.intValue() % 20 +1;
		index+=8;
		bi = new BigInteger(chromosome.substring(index, index + 8), 2);
		side2 = bi.intValue() % 20 +1;
		index+=8;
		bi = new BigInteger(chromosome.substring(index, index + 8), 2);
		wheel1 = bi.intValue() % 10 +1;
		index+=8;
		bi = new BigInteger(chromosome.substring(index, index + 8), 2);
		wheel2 = bi.intValue() % 10 +1;
		index+=8;
		bi = new BigInteger(chromosome.substring(index, index + 8), 2);
		sharedSide = bi.intValue() % 20 +1;
		index+=8;
		bi = new BigInteger(chromosome.substring(index, index + 32), 2);
		int c = bi.intValue();
		color = new Color(c);
		index+=32;
		bi = new BigInteger(chromosome.substring(index, index + 32), 2);
		c = bi.intValue();
		wheelColor = new Color(c);
	}
	
	public static String GenerateGenome(int bytes)
	{
		String out = "";
		for( int i = 0; i<bytes; i++)
		{
			for(int j = 0; j<8 ; j++)
			{
				if(Math.random() > .5)
				{
					out += "1";
				}
				else
				{
					out += "0";
				}
			}
		}
		return out;
	}
}
